package com.spring.hx.controller;

import com.spring.hx.config.GlobalConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController	
@RefreshScope
public class NacosProviderController {
	
	@Value("${server.port}")
	private String port;
	
	@Value("${user.name}")
	private String username;

	private static GlobalConfig globalConfig;
	@Autowired
	public void setGlobalConfig(GlobalConfig config) {
		globalConfig = config;
	}
	@GetMapping(value = "/echo/{message}")
	@ResponseBody
	public String echo(@PathVariable(value = "message") String message) {
		
		return message + ",provider.port:"+ port;
	}
	
	@GetMapping(value = "/test")
	public String test() {
		return username;
	}

	@GetMapping("/")
	public String test2(){
		int secs = globalConfig.getTokenExistSecs();
		System.err.println("读取配置："+secs);
		return "读取配置{globalconfig.tokenExpires}"+globalConfig.getTokenExistSecs();
	}
}
